﻿@{
    Lang lang = ViewBag.Lang;
    ViewBag.Title = @lang.CREATENEWS;
    Layout = "~/Views/Shared/_LayoutMember.cshtml";
}
<link href="/ContentMember/summernote.css" rel="stylesheet" type="text/css" />
@{
   DataHelper.New[] arrNews = ViewBag.arrNews;
}
<form method="post" action="/Admin/CreateNews" enctype="multipart/form-data" onsubmit="getHTML()">
<div class="row">
    <div class="col-md-12">
        <!-- start: FORM VALIDATION 2 PANEL -->
        <div class="panel panel-default">
            <div class="panel-heading">
                <i class="fa fa-external-link-square"></i>
                @if (arrNews[0].ID == 0)
                { 
                    @lang.CREATENEWS
                }
                else
                {
                    @lang.UPDATENEWS
                }
                @Html.Hidden("arrNews[0].ID", arrNews[0].ID)
                @Html.Hidden("arrNews[0].LangID", arrNews[0].LangID)
                @Html.Hidden("arrNews[0].TypeID", arrNews[0].TypeID)
                @Html.Hidden("arrNews[1].ID", arrNews[1].ID)
                @Html.Hidden("arrNews[1].LangID", arrNews[1].LangID)
                @Html.Hidden("arrNews[1].TypeID", arrNews[1].TypeID)
                <input type="hidden" name = "arrNews[0].Content" id="Content0" />
                <input type="hidden" name = "arrNews[1].Content" id="Content1" />
                <div class="panel-tools">
                    <a class="btn btn-xs btn-link panel-collapse collapses" href="#"></a><a class="btn btn-xs btn-link panel-config"
                        href="#panel-config" data-toggle="modal"><i class="fa fa-wrench"></i></a><a class="btn btn-xs btn-link panel-refresh"
                            href="#"><i class="fa fa-refresh"></i></a><a class="btn btn-xs btn-link panel-expand"
                                href="#"><i class="fa fa-resize-full"></i></a><a class="btn btn-xs btn-link panel-close"
                                    href="#"><i class="fa fa-times"></i></a>
                </div>
            </div>
            <div class="panel-body">
                <h2>
                    <i class="fa fa-pencil-square teal"></i>@lang.VIETNAM</h2>
                <p>
                    Create one account to manage everything you do with ClipOne, from your shopping
                    preferences to your ClipOne activity.
                </p>
                <hr>
                <form action="#" role="form" id="form2" novalidate="novalidate">
                <div class="row">
                    <div class="col-md-12">
                        <div class="errorHandler alert alert-danger no-display">
                            <i class="fa fa-times-sign"></i>You have some form errors. Please check below.
                        </div>
                        <div class="successHandler alert alert-success no-display">
                            <i class="fa fa-ok"></i>Your form validation is successful!
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label">
                                @lang.TITLE <span class="symbol required"></span>
                            </label>
                            <input type="text" class="form-control" id="firstname2" name="arrNews[0].Title" 
                            value="@arrNews[0].Title">
                        </div>
                        <div class="form-group">
                            <label class="control-label">
                                @lang.KEYWORD <span class="symbol required"></span>
                            </label>
                            <input type="text" class="form-control" id="lastname2"
                                name="arrNews[0].SEO" value="@arrNews[0].SEO">
                        </div>
                        <div class="form-group">
                            <div class="checkbox">
                                    <label>
                                        <div class="icheckbox_minimal-grey" style="position: relative;">
                                            <input type="checkbox" class="grey" @(arrNews[0].IsPin?"checked":"") name="arrNews[0].IsPin" id="service2" style="position: absolute;
                                                top: -10%; left: -10%; display: block; width: 120%; height: 120%; margin: 0px;
                                                padding: 0px; background-color: rgb(255, 255, 255); border: 0px; opacity: 0;
                                                background-position: initial initial; background-repeat: initial initial;">
                                            <ins class="iCheck-helper" style="position: absolute; top: -10%; left: -10%; display: block;
                                                width: 120%; height: 120%; margin: 0px; padding: 0px; background-color: rgb(255, 255, 255);
                                                border: 0px; opacity: 0; background-position: initial initial; background-repeat: initial initial;">
                                            </ins>
                                        </div>
                                        @lang.PINHOME
                                    </label>
                                </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label">
                                @lang.DESCRIPTION <span class="symbol required"></span>
                            </label>
                            <textarea  style="clear:both;width:100%" rows="5" cols="20"  name="arrNews[0].Description" required="required" rows="2">@arrNews[0].Description</textarea>
                        </div>
                        <div class="form-group">
                            <label class="control-label">
                                @lang.IMAGE <span class="symbol required"></span>
                            </label>
                            <input type="file" class="form-control" id="lastname2"
                                name="ImageFile1" value="@arrNews[0].Image">
                        </div>
                        <div class="form-group">
                            <label class="control-label">
                                Summernote <span class="symbol required"></span>
                            </label>
                            <div id="summernote0"  class=summernote">@Html.Raw(arrNews[0].Content)
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label">
                                @lang.TITLE <span class="symbol required"></span>
                            </label>
                            <input type="text" class="form-control" id="firstname2" name="arrNews[1].Title" 
                            value="@arrNews[1].Title">
                        </div>
                        <div class="form-group">
                            <label class="control-label">
                                @lang.KEYWORD <span class="symbol required"></span>
                            </label>
                            <input type="text" class="form-control" id="lastname2"
                                name="arrNews[1].SEO" value="@arrNews[1].SEO">
                        </div>
                        <div class="form-group">
                            <div class="checkbox">
                                    <label>
                                        <div class="icheckbox_minimal-grey" style="position: relative;">
                                            <input type="checkbox" class="grey" @(arrNews[1].IsPin?"checked":"") name="arrNews[1].IsPin" id="service2" style="position: absolute;
                                                top: -10%; left: -10%; display: block; width: 120%; height: 120%; margin: 0px;
                                                padding: 0px; background-color: rgb(255, 255, 255); border: 0px; opacity: 0;
                                                background-position: initial initial; background-repeat: initial initial;">
                                            <ins class="iCheck-helper" style="position: absolute; top: -10%; left: -10%; display: block;
                                                width: 120%; height: 120%; margin: 0px; padding: 0px; background-color: rgb(255, 255, 255);
                                                border: 0px; opacity: 0; background-position: initial initial; background-repeat: initial initial;">
                                            </ins>
                                        </div>
                                        @lang.PINHOME
                                    </label>
                                </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label">
                                @lang.DESCRIPTION <span class="symbol required"></span>
                            </label>
                            <textarea  style="clear:both;width:100%" rows="5" cols="20"  name="arrNews[1].Description" required="required" rows="2">@arrNews[0].Description</textarea>
                        </div>
                        <div class="form-group">
                            <label class="control-label">
                                @lang.IMAGE <span class="symbol required"></span>
                            </label>
                            <input type="file" class="form-control" id="lastname2"
                                name="ImageFile2" value="@arrNews[1].Image">
                        </div>
                        <div class="form-group">
                            <label class="control-label">
                                Summernote <span class="symbol required"></span>
                            </label>
                            <div id="summernote1" class=summernote">@Html.Raw(arrNews[1].Content)
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12">
                        
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12">
                        <div>
                            <span class="symbol required"></span>Required Fields
                            <hr>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-8">
                        <p>
                            By clicking REGISTER, you are agreeing to the Policy and Terms &amp; Conditions.
                        </p>
                    </div>
                    <div class="col-md-4">
                        <button class="btn btn-yellow btn-block" type="submit">
                            Register <i class="fa fa-arrow-circle-right"></i>
                        </button>
                    </div>
                </div>
                </form>
            </div>
        </div>
        <!-- end: FORM VALIDATION 2 PANEL -->
    </div>
</div>
</form>
<script src="/ContentMember/summernote.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#summernote0').summernote({
            height: "500px",
            tabsize: 2, onImageUpload: function (files, editor, welEditable) {
            alert("test")
                sendFile(files[0], editor, welEditable);
            }
        });
    });
    $(document).ready(function () {
        $('#summernote1').summernote({
            height: 500,
            tabsize: 2, onImageUpload: function (files, editor, welEditable) {
                sendFile(files[0], editor, welEditable);
            }
        });
    });
    function getHTML() {

        $("#Content0").val($('#summernote0').code());
        $("#Content1").val($('#summernote1').code());
    }
</script>


<script type="text/javascript">
    function sendFile(file, editor, welEditable) {
        data = new FormData();
        data.append("file", file);
        url = "http://localhost/spichlerz/uploads";
        $.ajax({
            data: data,
            type: "POST",
            url: url,
            cache: false,
            contentType: false,
            processData: false,
            success: function (url) {
                editor.insertImage(welEditable, url);
            }
        });
    }
</script>
